#include"tree.h"

void PrevOrder(BTNode* root)
{
	if (root == NULL)
	{
		return;
	};
	printf("%c ", root->data);
	PrevOrder(root->left);
	PrevOrder(root->right);
}

void InOrder(BTNode* root)
{
	if (root == NULL)
	{
		return;
	 }
	InOrder(root->left);
	printf("%c ", root->data);
	InOrder(root->right) ;
}

void Post(BTNode* root)
{
	if (root == NULL)
	{
		return;
	}
	Post(root->left);
	Post(root->right);
	printf("%c ", root->data);
}

void TreeSize(BTNode* root, int* psize)
{
	if (root == NULL)
	{
		return;
	}
	(*psize)++;
	TreeSize(root->left,psize);
	TreeSize(root->right,psize);
}
int TreeSize1(BTNode* root)
{
	return root == NULL ? 0 : TreeSize1(root->left) + TreeSize1(root->right) + 1;
}

int TreeLeafSize(BTNode* root)
{
	if (root == NULL)
		return 0;
	if (root->left == NULL && root->right == NULL)
		return 1;
	return TreeLeafSize(root->left) + TreeLeafSize(root->right);
}

void LevelOrder(BTNode* root)
{
	QNode q;
	QueueInit(&q);
	if (root)
		QueuePush(&q, root);
	while (QueueEmpty(&q))
	{
		BTNode* front = QueueFront(&q);
		QueuePop(&q);
		printf("%c ", front->data);		 
		if (front->left)
		{
			QueuePush(&q, front->left);
		}
		if (front->right)
		{
			QueuePush(&q, front->right);
		}
	}
}